package com.es.util.file;

import cn.hutool.core.io.resource.ClassPathResource;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 配置文件工具类
 *
 * @author Will
 */
public class ConfigUtil {

    /**
     * 获取配置值
     *
     * @param path
     * @param key
     * @return
     * @throws IOException
     */
    public static Object getFromProperties(String path, String key) throws IOException {
        Properties properties = new Properties();
        InputStream fileInputStream = new FileInputStream(path);
        properties.load(fileInputStream);
        return properties.get(key);
    }

    /**
     * 获取配置值
     *
     * @param key
     * @return
     * @throws IOException
     */
    public static Object getDefaultFromProperties(String key) {
        try {
            String path = FileUtil.replaceName(new ClassPathResource("ex.properties").getAbsolutePath());
            return getFromProperties(path, key);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
